<template>
  <div class="lqlb">
    <div class="head">
      <div class="province">
        <span>省<span class="bank32"></span>份：</span>
        <el-select v-model="sfmc" filterable placeholder="请选择">
          <el-option
            v-for="item in sfmcs"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </div>
      <div class="type">
        <span>录取类别：</span>
        <el-select v-model="lqlb" filterable placeholder="请选择">
          <el-option
            v-for="item in lqlbs"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </div>
      <div class="name">
        <span>姓<span class="bank16"></span>名：</span>
        <el-input v-model="name" placeholder="请输入内容"></el-input>
      </div>
      <div class="number">
        <span>考生号：</span>
        <el-input v-model="number" placeholder="请输入内容"></el-input>
      </div>
      <button @click="query">查询</button>
      <button @click="reset">重置</button>
      <div class="update-type">
        <span>修正计划类别：</span>
        <el-select v-model="jhlb" filterable placeholder="请选择">
          <el-option
            v-for="item in lqlbs"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </div>
      <div class="update-zy">
        <span
          >修<span class="bank11"></span>正<span class="bank11"></span>专<span
            class="bank11"
          ></span
          >业：</span
        >
        <el-input v-model="zymc" placeholder="请输入内容"></el-input>
      </div>
      <!-- <div class="update-kl">
        <span
          >修<span class="bank11"></span>正<span class="bank11"></span>科<span
            class="bank11"
          ></span
          >类：</span
        >
        <el-select v-model="kl" filterable placeholder="请选择">
          <el-option
            v-for="item in kls"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </div> -->
      <button @click="change">批量修改</button>
    </div>

    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      height="640"
      border
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="80"> </el-table-column>
      <el-table-column prop="xm" label="姓名" width="240"> </el-table-column>
      <el-table-column prop="ksh" label="考生号" width="350"> </el-table-column>
      <el-table-column prop="sfdm" label="省份名称" width="300">
      </el-table-column>
      <el-table-column prop="lqzy" label="专业名称" width="350">
      </el-table-column>
      <el-table-column prop="kldm" label="录取类别名称"> </el-table-column>
      <!-- <el-table-column prop="kl" label="科类名称"> </el-table-column> -->
    </el-table>
  </div>
</template>

<script>
import { request } from "../../network/request";
export default {
  name: "",
  data() {
    return {
      sfmc: "",
      lqlb: "",
      jhlb: "",
      name: "",
      number: "",
      zymc: "",
      sfmcs: [
        {
          value: "北京",
          label: "北京",
        },
        {
          value: "天津",
          label: "天津",
        },
        {
          value: "上海",
          label: "上海",
        },
        {
          value: "重庆",
          label: "重庆",
        },
        {
          value: "河北",
          label: "河北",
        },
        {
          value: "山西",
          label: "山西",
        },
        {
          value: "辽宁",
          label: "辽宁",
        },
        {
          value: "吉林",
          label: "吉林",
        },
        {
          value: "黑龙江",
          label: "黑龙江",
        },
        {
          value: "江苏",
          label: "江苏",
        },
        {
          value: "浙江",
          label: "浙江",
        },
        {
          value: "安徽",
          label: "安徽",
        },
        {
          value: "福建",
          label: "福建",
        },
        {
          value: "江西",
          label: "江西",
        },
        {
          value: "山东",
          label: "山东",
        },
        {
          value: "河南",
          label: "河南",
        },
        {
          value: "湖北",
          label: "湖北",
        },
        {
          value: "湖南",
          label: "湖南",
        },
        {
          value: "广东",
          label: "广东",
        },
        {
          value: "海南",
          label: "海南",
        },
        {
          value: "四川",
          label: "四川",
        },
        {
          value: "贵州",
          label: "贵州",
        },
        {
          value: "云南",
          label: "云南",
        },
        {
          value: "陕西",
          label: "陕西",
        },
        {
          value: "甘肃",
          label: "甘肃",
        },
        {
          value: "青海",
          label: "青海",
        },
        {
          value: "台湾",
          label: "台湾",
        },
        {
          value: "内蒙古",
          label: "内蒙古",
        },
        {
          value: "广西",
          label: "广西",
        },
        {
          value: "西藏",
          label: "西藏",
        },
        {
          value: "宁夏",
          label: "宁夏",
        },
        {
          value: "新疆",
          label: "新疆",
        },
        {
          value: "香港",
          label: "香港",
        },
        {
          value: "澳门",
          label: "澳门",
        },
      ],
      lqlbs: [
        {
          value: "理科普通类",
          label: "理科普通类",
        },
        {
          value: "文科普通类",
          label: "文科普通类",
        },
        {
          value: "保送生",
          label: "保送生",
        },
        {
          value: "广播电视编导术科类统考",
          label: "广播电视编导术科类统考",
        },
      ],
      tableData: [],
      multipleSelection: [],
    };
  },
  methods: {
    query() {
      if (this.number != "") {
        request({
          url: "http://118.31.51.131:8081/api/zsxt/lqgl/ksxx/cxksh",
          method: "post",
          params: {
            ksh: this.number,
            token: sessionStorage.getItem("token"),
          },
        })
          .then((value) => {
            console.log(value);
            if (value.data != "输入错误") {
              this.tableData = [];
              this.tableData.push(value.data)
            } else {
              this.tableData = [];
            }
          })
          .catch((err) => {
            console.log(err);
          });
      } else if (this.name != "") {
        request({
          url: "http://118.31.51.131:8081/api/zsxt/lqgl/ksxx/cxxm",
          method: "post",
          params: {
            xm: this.name,
            token: sessionStorage.getItem("token"),
          },
        })
          .then((value) => {
            console.log(value);
            if (value.data != "输入错误") {
              this.tableData = value.data;
            } else {
              this.tableData = [];
            }
          })
          .catch((err) => {
            console.log(err);
          });
      } else if (this.sfmc != "" && this.lqlb != "") {
        request({
          url: "http://118.31.51.131:8081/api/zsxt/lqgl/ksxx/cxfs",
          method: "post",
          params: {
            sfdm: this.sfmc,
            kldm: this.lqlb,
            token: sessionStorage.getItem("token"),
          },
        })
          .then((value) => {
            console.log(value);
            if (value.data != "输入错误") {
              this.tableData = value.data;
            } else {
              console.log(1);
              this.tableData = [];
            }
          })
          .catch((err) => {
            console.log(err);
          });
      }
    },
    reset() {
      this.sfmc = "";
      this.lqlb = "";
      this.name = "";
      this.number = "";
    },
    change() {
      if (this.jhlb == "" && this.zymc == "") {
        alert("请修改");
        return;
      }
      let copy = JSON.parse(JSON.stringify(this.multipleSelection));
      if (this.jhlb != "") {
        for (let item of copy) {
          item.kldm = this.jhlb;
        }
        if (this.zymc != "") {
          for (let item of copy) {
            item.lqzy = this.zymc;
          }
        }
        request({
          url: "http://118.31.51.131:8081/api/zsxt/lqgl/ksxx/xgxx",
          method: "post",
          data: copy,
          params: {
            token: sessionStorage.getItem("token"),
          },
        }).then((value) => {
          console.log(value);
          this.query();
          alert("修改成功");
        });
      } else if (this.zymc != "") {
        for (let item of copy) {
          item.lqzy = this.zymc;
        }
        request({
          url: "http://118.31.51.131:8081/api/zsxt/lqgl/ksxx/xgxx",
          method: "post",
          data: copy,
          params: {
            token: sessionStorage.getItem("token"),
          },
        }).then((value) => {
          console.log(value);
          this.query();
          console.log(this.multipleSelection);
          alert("修改成功");
        });
      }
    },
    handleSelectionChange(val) {
      console.log(val);
      this.multipleSelection = val;
    },
  },
  beforeCreate() {
    if (sessionStorage.getItem("token") == null) {
      this.$router.push("/login");
    } else {
      let token = sessionStorage.getItem("token");
      let length = sessionStorage.getItem("token").length;
      if (token[length - 4] == "0") {
        this.$router.replace("/login");
      }
    }
  },
  components: {},
};
</script>

<style scoped>
.head {
  height: 160px;
  border-bottom: 1px solid #000;
}
.el-input {
  width: 200px;
}
.bank11 {
  margin-left: 11px;
}
.bank16 {
  margin-left: 16px;
}
.bank32 {
  margin-left: 32px;
}
.province {
  position: absolute;
  top: 15px;
  left: 25px;
}
.type {
  position: absolute;
  top: 85px;
  left: 25px;
}
.name {
  position: absolute;
  top: 15px;
  left: 340px;
}
.number {
  position: absolute;
  top: 85px;
  left: 340px;
}
.head button {
  width: 100px;
  height: 45px;
  border: none;
  outline: none;
  cursor: pointer;
  color: #fff;
  background-color: rgb(192, 51, 56);
}
button:active {
  opacity: 0.8;
}
.head button:nth-of-type(1) {
  position: absolute;
  top: 10px;
  left: 680px;
}
.head button:nth-of-type(2) {
  position: absolute;
  top: 85px;
  left: 680px;
}
.update-type {
  position: absolute;
  top: 15px;
  left: 960px;
}
.update-zy {
  position: absolute;
  top: 85px;
  left: 960px;
}
.update-kl {
  position: absolute;
  top: 105px;
  left: 960px;
}
.head button:nth-of-type(3) {
  position: absolute;
  top: 55px;
  left: 1360px;
}
.el-table {
  width: 100%;
}
.lqlb ::v-deep .el-table .cell {
  text-align: center;
}
</style>